/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package optimizacion.problemas;

import java.io.*;

/**
 *
 * @author USUARIO
 */
public class TSPFileReader {
    private int node;
    private double [][] coordinates;
    private String fileName;

    public TSPFileReader(int node, double[][] coordinates, String fileName) {
        this.node = node;
        this.coordinates = coordinates;
        this.fileName = fileName;
    }

    public void readFile() throws FileNotFoundException, UnsupportedEncodingException, IOException{
        FileReader file = new FileReader(fileName);
        BufferedReader reader = new BufferedReader(file);
        String line = null;
        int i = 0;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (line.matches("\\b([0-9.]+[ ]*)*\\b")) {
                //System.out.println(line);
                String[] numbers = line.split(" ");
                coordinates[i][0] = Double.valueOf(numbers[1]);
                coordinates[i][1] = Double.valueOf(numbers[2]);
                i++;
            }
            else{
                //System.out.println("no");
            }
        }
        reader.close();
    }
    
    public double[][] getCoordinates() {
        return coordinates;
    }

    public int getNode() {
        return node;
    }
    
    
}
